set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/* *******************************************************************
** DATE :
** Writer :
** Memo :
******************************************************************** */
CREATE PROCEDURE [dbo].[TSP_Recruit_Modify]
(
	@IsTransaction	tinyint			= 0
,	@ErrorCode		int				= 0		OUTPUT
,	@ErrorMessage	nvarchar( 1000 )= ''	OUTPUT

,	@n4RecruitNo	int	
,	@strName	nvarchar(60)		= NULL	
,	@strPersonalNo	varchar(50)		= NULL	
,	@strPhone	varchar(14)		= NULL	
,	@strEmail	varchar(200)		= NULL	
,	@strPostNo	varchar(10)		= NULL	
,	@strAddress	nvarchar(600)		= NULL	
,	@strHopeStore	nvarchar(400)		= NULL	
,	@n1JobTime	tinyint		= NULL	
,	@strAcademic	nvarchar(MAX)		= NULL	
,	@strCareer	nvarchar(MAX)		= NULL	
,	@strLicense	nvarchar(MAX)		= NULL	
,	@strFileURL	varchar(200)		= NULL	
,	@n1Status	tinyint		= NULL	
,	@strManagerName	nvarchar(50)	= NULL	
,	@strDescription	nvarchar(MAX)	= NULL	
)
as
Set NOCOUNT ON

-- Frk Default Value
DECLARE @FrkDateNow DateTime
DECLARE @FrkRowCount int
DECLARE @FrkTranCount int
DECLARE @FrkErrorCode int
DECLARE @FrkErrorMessage nvarchar( 1000 )
Set @FrkDateNow = GetDate()
set @FrkTranCount = @@TRANCOUNT
-- Frk Check


If ( @IsTransaction = 0 )
Begin
	If ( @FrkTranCount < 1 )
	Begin
		Set @FrkErrorCode = -1
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Else If ( @FrkTranCount > 1 )
	Begin
		Set @FrkErrorCode = -2
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
End
Else
Begin
	If ( @FrkTranCount <> 0 )
	Begin
		Set @FrkErrorCode = -3
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Begin Tran
End

-- Implementation


UPDATE
	dbo.TB_Recruit
SET
	strName = IsNull( @strName, strName )
,	strPersonalNo = IsNull( @strPersonalNo, strPersonalNo )
,	strPhone = IsNull( @strPhone, strPhone )
,	strEmail = IsNull( @strEmail, strEmail )
,	strPostNo = IsNull( @strPostNo, strPostNo )
,	strAddress = IsNull( @strAddress, strAddress )
,	strHopeStore = IsNull( @strHopeStore, strHopeStore )
,	n1JobTime = IsNull( @n1JobTime, n1JobTime )
,	strAcademic = IsNull( @strAcademic, strAcademic )
,	strCareer = IsNull( @strCareer, strCareer )
,	strLicense = IsNull( @strLicense, strLicense )
,	strFileURL = IsNull( @strFileURL, strFileURL )
,	n1Status = IsNull( @n1Status, n1Status )
,	dtModifyDate = @FrkDateNow
,	strManagerName = IsNull( @strManagerName, strManagerName )
,	strDescription = IsNull( @strDescription, strDescription )
WHERE
	n4RecruitNo = @n4RecruitNo


-- Frk Error Check
SELECT
	@FrkErrorCode = @@ERROR
,	@FrkRowCount = @@RowCount

-- End

COMPLETE:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Commit Tran
		End
	End
	SET @ErrorCode = 0
	SET @ErrorMessage = ''
	return 0
ERROR:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Rollback Tran
		End
	End
	SET @ErrorCode = @FrkErrorCode
	SET @ErrorMessage = @FrkErrorMessage
	return @FrkErrorCode
